

package com.hazelcast.cp.internal;

import com.hazelcast.cp.CPMember;

import java.util.Collection;
import java.util.Objects;

/**
 * Data class used for sharing Raft group information to clients via
 * {@link com.hazelcast.client.impl.protocol.codec.ClientAddCPGroupViewListenerCodec}.
 * CP to AP UUID mapping sent separately, to avoid duplicate entries between groups.
 */
public class RaftGroupInfo {
    private final RaftGroupId groupId;
    private final CPMember leader;
    private final Collection<CPMember> followers;

    public RaftGroupInfo(RaftGroupId groupId, CPMember leader, Collection<CPMember> followers) {
        this.groupId = groupId;
        this.leader = leader;
        this.followers = followers;
    }

    public RaftGroupId getGroupId() {
        return groupId;
    }

    public CPMember getLeader() {
        return leader;
    }

    public Collection<CPMember> getFollowers() {
        return followers;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        RaftGroupInfo that = (RaftGroupInfo) o;
        return Objects.equals(groupId, that.groupId) && Objects.equals(leader, that.leader) && Objects.equals(followers, that.followers);
    }

    @Override
    public int hashCode() {
        return Objects.hash(groupId, leader, followers);
    }

    @Override
    public String toString() {
        return "RaftGroupInfo{" + "groupId=" + groupId + ", " + "leader=" + leader + ", " + "followers=" + followers + ", " + "}";
    }
}
